﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace XamlInspector.Presentation
{
    public sealed partial class PropertiesControl : UserControl
    {
        public PropertiesControl()
        {
            InitializeComponent();
        }

        public ICollectionView Properties
        {
            get { return (ICollectionView)GetValue(PropertiesProperty); }
            set { SetValue(PropertiesProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Properties.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PropertiesProperty =
            DependencyProperty.Register("Properties", typeof(ICollectionView), typeof(PropertiesControl), new PropertyMetadata(null, OnPropertiesChanged));

        private static void OnPropertiesChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var control = (PropertiesControl)sender;
            control.UpdateProperties((ICollectionView)e.NewValue);
        }


        private void UpdateProperties(ICollectionView propertyList)
        {
            if (propertyList != null)
            {
                properties.ItemsSource = propertyList;
            }
        }

    }
}
